Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@metamask/swappable-obj-proxy

Package Overview
Dependencies
Maintainers
9
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@metamask/swappable-obj-proxy

Tools for creating `Proxy`s around objects that are swappable via setTarget

  • 2.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
9
Created
Source

createSwappableProxy

Creates a Proxy around any object. Retarget the proxy with setTarget.

Installation

yarn add @metamask/swappable-obj-proxy

or

npm install @metamask/swappable-obj-proxy

Usage

createSwappableProxy

const { createSwappableProxy } = require('@metamask/swappable-obj-proxy');

const original = { sayHello: () => 'hi' };
const next = { sayHello: () => 'haay' };
const proxy = createEventEmitterProxy(original);

proxy.sayHello(); //=> "hi"
proxy.setTarget(next);
proxy.sayHello(); //=> "haay"

createEventEmitterProxy

Creates a Proxy around an EventEmitter. If the proxy has setTarget called with a different EventEmitter, all events will be removed from the old target and transferred to the new EventEmitter.

const { createEventEmitterProxy } = require('@metamask/swappable-obj-proxy');

const original = new EventEmitter();
const next = new EventEmitter();
const proxy = createEventEmitterProxy(original);

proxy.on('event', () => console.log('saw event!'));

// triggers the event handler
original.emit('event');

// moves listeners over to next
proxy.setTarget(next);

// does NOT trigger the event handler
original.emit('event');
// DOES trigger the event handler
next.emit('event');

FAQs

Package last updated on 06 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc